var request = require('../../../utils/httpUtils.js');

/**
 * 获取已领取该商品的人
 */
function getObtainSuccessPeople(param, successCall) {
  request.Get(false, request.api.obtain_success, param,
    function (success) {
      successCall(success)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 根据商品ID获取该商品详情
 */
function getGoodsDetails(param, successCall, errorCall) {
  request.Get(false, request.api.goods_details, param,
    function (success) {
      if (success) {
        successCall(success)
      }
    },
    function (error) {
      errorCall(error)
    })
}

/**
 * 打赏商品
 */
function praiseGoods(param, successCall) {
  getApp().func.Post(false, request.api.praise_candy, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 根据商品ID获取商品的所有打赏
 */
function getRewardData(param, successCall) {
  request.Get(false, request.api.reward, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      // wx.showToast({
      //   title: error.data.message,
      //   icon: 'none',
      //   duration: 2000,
      // })
    })
}

/**
 * 我的砍价记录
 */
function getCutFlowerData(param, successCall) {
  getApp().func.Post(false, request.api.cut_goods_records, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      // wx.showToast({
      //   title: error.data.message,
      //   icon: 'none',
      //   duration: 2000,
      // })
    })
}

/**
 * 帮助好友砍价
 */
function cutMoney(param, successCall) {
  getApp().func.Post(false, request.api.cut_goods, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 用户可能认识的人
 */
function getUserFollower(successCall) {
  return request.Get(false, request.api.user_follower,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 故事信息详情查询
 */
function getStoryDetails(param, successCall) {
  getApp().func.Post(false, request.api.story_details, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 购买商品  要了
 */
function payDefultGoods(param, successCall) {
  getApp().func.Post(false, request.api.default_pay, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 当前用户是否已关注过目标用户，0没有，1已关注
 */
function getFansPeople(param, successCall) {
  getApp().func.Post(false, request.api.userfans_get_fans, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 修改关注的人
 */
function setFansData(param, successCall) {
  getApp().func.Post(false, request.api.put_fans, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 取消收藏信息
 */
function deleteCollection(param, successCall) {
  getApp().func.Post(false, request.api.user_fav_del, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 *  添加收藏信息
 */
function addCollection(param, successCall) {
  getApp().func.Post(true, request.api.user_fav, param,
    function (data) {
      if (data) {
        successCall(data)
      }
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 查询当前用户是否对此商品/视频是否收藏
 * 0已收藏，否则为未收藏
 */
function getCollection(param, successCall) {
  getApp().func.Post(false, request.api.get_collection, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 根据当前商品ID下参与竞拍的用户
 */
function getBiddersData(param, successCall) {
  getApp().func.Post(false, request.api.get_bidders, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 竞拍确认出果冻
 */
function commitCandy(param, successCall) {
  getApp().func.Post(true, request.api.commit_info, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 查询竞拍信息
 */
function queryBiddersInfo(param, successCall) {
  getApp().func.Post(false, request.api.bidder_info, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 获取用户默认地址
 */
function getDefaultAddress(param, successCall) {
  return request.Get(false, request.api.getDefault_address, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 获取运费费用
 */
function getFreight(param, successCall) {
  getApp().func.Post(false, request.api.get_freight, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      // wx.showToast({
      //   title: error.data.message,
      //   icon: 'none',
      //   duration: 2000,
      // })
    })
}

/**
 * 获取规则信息
 */
function getRule(param, successCall) {
  getApp().func.Get(false, request.api.get_setting, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 存入微信分享记录
 */
function saveShare(param, successCall) {
  getApp().func.Post(false, request.api.save_share, param,
    function (data) {
      successCall(data)
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    })
}

/**
 * 抢兑一口价商品下单
 */
function putRobBuy(params,success) {
  getApp().func.Post(false, getApp().api.put_rob_buy, params,
    function (data) {
      typeof success == "function" && success(data);
    },
    function (error) {
      wx.showToast({
        title: error.data.message,
        icon: 'none',
        duration: 2000,
      })
    });
}

exports.putRobBuy = putRobBuy;
exports.saveShare = saveShare;
exports.getRule = getRule;
exports.getFreight = getFreight;
exports.getDefaultAddress = getDefaultAddress;
exports.queryBiddersInfo = queryBiddersInfo;
exports.getObtainSuccessPeople = getObtainSuccessPeople;
exports.getGoodsDetails = getGoodsDetails;
exports.praiseGoods = praiseGoods;
exports.getRewardData = getRewardData;
exports.getCutFlowerData = getCutFlowerData;
exports.cutMoney = cutMoney;
exports.getUserFollower = getUserFollower;
exports.getStoryDetails = getStoryDetails;
exports.payDefultGoods = payDefultGoods;
exports.getFansPeople = getFansPeople;
exports.setFansData = setFansData;
exports.addCollection = addCollection; 
exports.deleteCollection = deleteCollection; 
exports.getCollection = getCollection; 
exports.getBiddersData = getBiddersData;
exports.commitCandy = commitCandy; 